package com.fira.api.controller;

import com.fira.api.domain.dto.LoginDTO;
import com.fira.cms.domain.CmsArticle;
import com.fira.cms.domain.CmsBanner;
import com.fira.cms.service.ICmsArticleService;
import com.fira.cms.service.ICmsBannerService;
import com.fira.common.core.controller.BaseController;
import com.fira.common.core.domain.AjaxResult;
import com.fira.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Api(value="首页信息接口",tags={"首页信息"})
@Controller
@RequestMapping("/api/cms")
public class CmsController extends ApiController {
    @Autowired
    private ICmsBannerService cmsBannerService;
    @Autowired
    private ICmsArticleService cmsArticleService;

    @ApiOperation(value="查询banner列表",tags={"查询banner列表"},notes="")
    @PostMapping("/bannerList")
    @ResponseBody
    public AjaxResult getBannerList(HttpServletRequest request){
        LoginDTO loginDTO = getLogin(request);
        String tenantId = loginDTO.getCurrentTenantId();
        CmsBanner banner = new CmsBanner();
        banner.setTenantId(tenantId);
        return AjaxResult.success("查询成功",cmsBannerService.selectCmsBannerList(banner));
    }

    @ApiOperation(value="查询文章列表",tags={"查询文章列表"},notes="")
    @PostMapping("/articleList")
    @ResponseBody
    public AjaxResult getArticleList(HttpServletRequest request){
        LoginDTO loginDTO = getLogin(request);
        String tenantId = loginDTO.getCurrentTenantId();
        CmsArticle article = new CmsArticle();
        article.setTenantId(tenantId);
        return AjaxResult.success("查询成功",cmsArticleService.selectCmsArticleList(article));
    }
}
